import {ref} from 'vue'
import {defineStore} from "pinia"

/**
 * 用户token状态管理
 * @type {StoreDefinition<"userToken", _ExtractStateFromSetupStore<{userToken: Ref<UnwrapRef<string>>, setToken: function(*): void, removeToken: function(): void}>, _ExtractGettersFromSetupStore<{userToken: Ref<UnwrapRef<string>>, setToken: function(*): void, removeToken: function(): void}>, _ExtractActionsFromSetupStore<{userToken: Ref<UnwrapRef<string>>, setToken: function(*): void, removeToken: function(): void}>>}
 */
export const userInfoStore = defineStore('userInfo',()=>{
    //定义一个属性
    const userInfo=ref('')

    //新增userInfo
    const setUserInfo = (newToken) => {
        userInfo.value=newToken
    }
    //删除userInfo
    const removeUserInfo = ()=>{
        userInfo.value=''
    }

    const getUserInfo = () => {
        return userInfo.value
    }

    return {userInfo,setUserInfo,removeUserInfo,getUserInfo}
},{
    //持久化
    persist:true
})